//
//  HPFestivalCell.m
//  HappyPenguin
//
//  Created by zhuangyihang on 1/9/16.
//  Copyright © 2016 zhuangyihang. All rights reserved.
//

#import "HPFestivalCell.h"
#import "UIConstants.h"
#import "UIImage+Common.h"
static const NSInteger kPortraitWidth = 35;
static const NSInteger kPortraitMarginLeft = 10;


static const NSInteger kBadgeViewFontSize = 12;
static const NSInteger kBadgeViewWidth = 17;
static const NSInteger kBadgeViewMarginRight = 0;

@interface HPFestivalCell()

@property (nonatomic, strong) UILabel *badgeLabel;

@end

@implementation HPFestivalCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.iconImageView = [UIImageView new];
        [self.contentView addSubview:self.iconImageView];
        [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(kPortraitWidth);
            make.centerY.equalTo(self.contentView);
            make.left.mas_equalTo(kPortraitMarginLeft);
        }];
        self.iconImageView.layer.cornerRadius = kPortraitWidth/2;
        self.iconImageView.clipsToBounds = YES;
        self.iconImageView.contentMode = UIViewContentModeScaleAspectFill;
        
        //使cell上的标题和分割线都往右边移动
        self.imageView.image = [UIImage imageWithColor:[UIColor clearColor] withFrame:CGRectMake(0, 0, 30, 30)];
        
        self.textLabel.font = [UIConstants getFont:16];
        self.detailTextLabel.font = [UIConstants getFont:13];
        
        self.textLabel.textColor = [UIColor colorWithRGB:0x505050];
        self.detailTextLabel.textColor = [UIColor colorWithRGB:0x606060];
        
        self.badgeLabel = [UILabel new];
        [self.contentView addSubview:self.badgeLabel];
        self.badgeLabel.layer.cornerRadius = kBadgeViewWidth/2;
        self.badgeLabel.backgroundColor = [UIColor colorWithRGB:0xd42f21];
        self.badgeLabel.clipsToBounds = YES;
        [self.badgeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(kBadgeViewWidth);
            make.centerY.equalTo(self.contentView);
            make.right.equalTo(self.contentView).offset(kBadgeViewMarginRight);
        }];
        self.badgeLabel.font = [UIConstants getFont:kBadgeViewFontSize];
        self.badgeLabel.textColor = [UIColor whiteColor];
        self.badgeLabel.textAlignment = NSTextAlignmentCenter;

    }
    return self;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

+ (CGFloat)getCellHeight{
    return 50;
}

- (void)setBadgeView:(NSInteger)badge{
    self.badgeLabel.text = [NSString stringWithFormat:@"%ld",(long)badge];
}
@end
